package vsqlbuilder.gui.diagram;

import java.awt.Point;
import java.util.ArrayList;
import java.util.List;

import vsqlbuilder.logic.Column;

public class GAnchorPoint {
	private GTable ownerGTable;
	private Column ownerColumn;
	private Point LocationRight,LocationLeft;
	private List<GJoinRelation> joins;
	
	//NOTE:Before get a correct position of the AnchorPoint, please call to function CalculateLocations
	public GAnchorPoint(GTable ownerGTable,Column sourceColumn){
		joins = new ArrayList<GJoinRelation>();
		this.ownerGTable=ownerGTable;
		this.ownerColumn=sourceColumn;
		LocationRight=new Point();
		LocationLeft=new Point();
		CalculateLocations();
	}
	
	public void addJoinRelation(GJoinRelation gjr){
		this.joins.add(gjr);
	}
	
	public void removeJoinRelation(GJoinRelation gjr){
		this.joins.remove(gjr);
	}
	
	public void CalculateLocations(){
		//Give arbitrary point at left to get coordinates.
		this.LocationLeft=ownerGTable.getJoinAtColPos(ownerColumn, new Point(ownerGTable.getRectangle().x-10,ownerGTable.getRectangle().y));
		//Give arbitrary point at right to get coordinates. 
		this.LocationRight=ownerGTable.getJoinAtColPos(ownerColumn, new Point(ownerGTable.getRectangle().x+ownerGTable.getWidth()+10,ownerGTable.getRectangle().y));
	}
	
	public Point getRightLocation(){
		return this.LocationRight;
	}
	
	public Point getLeftLocation(){
		return this.LocationLeft;
	}
	
	public String getColumnName(){
		return this.ownerColumn.getName();
	}
	
	public List<GJoinRelation> getJoinsList(){
		return this.joins;
	}
	
	public int getOwnerGTableMiddleX(){
		return this.ownerGTable.getRectangle().getLocation().x+this.ownerGTable.getWidth();
	}
	
	public Column getownerColumn(){
		return this.ownerColumn;
	}
	
}
